package com.shishuo.cdn.action;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.shishuo.cdn.dao.IdcDao;
import com.shishuo.cdn.entity.User;
import com.shishuo.cdn.service.IdcService;

/**
 * IDC价格
 * 
 * @author wzc
 * 
 */

@Controller
@RequestMapping("/idc")
public class IdcAction extends BaseAction {
	
	@Autowired
	private IdcService idcService;

	/**
	 * 
	 * 描述：IDC价格获取
	 * 创建人： 魏泽超
	 * 创建时间: 2016-4-6 下午5:46:04
	 * @version
	 */
	@ResponseBody
	@RequestMapping(value = "/IdcPrice.json", method = RequestMethod.GET)
	public Map<String,Object> IdcPrice(HttpServletRequest request, ModelMap modelMap) {
		User user = (User) request.getSession().getAttribute("user");
		Map<String,Object> map=new HashMap<String,Object>();
		if(null==user){
			map.put("status", 1);
			map.put("data", "请先登录");
			return map;
		}
/*		String idcList=idcService.queryIdcList("IDC");
		String idcLists[] ={};
		String idcPriceList[] ={};
		Double idcDoublePriceList[] ={};
		if(null!=idcList && !("").equals(idcList)){
			idcLists=idcList.split(",");
			idcPriceList=new String[idcLists.length];
			idcDoublePriceList=new Double[idcLists.length];
			for (int i = 0; i < idcLists.length; i++) {
				idcPriceList[i]=idcService.getIdcPrice(idcLists[i]);
				idcDoublePriceList[i]=Double.parseDouble(idcService.getIdcPrice(idcLists[i]))*1.5;
			}
			map.put("status", 0);
			map.put("single", idcPriceList);
			map.put("double", idcDoublePriceList);
		}*/
		Map<String,Object> deviceMap=getDevicePrice();
		if(null!=deviceMap){
			map.put("status", 0);
			map.put("deviceMap", deviceMap);
		}
		System.out.println("IDC价格获取---");
		return map;
	}
	
	/**
	 * 
	 * 描述：获取设备信息
	 * 创建人： 魏泽超
	 * 创建时间: 2016-4-7 上午9:56:50
	 * @version
	 */
	private Map<String,Object> getDevicePrice(){
		List<Map<String,Object>> mapList=idcService.getDevicePrice();
		Map<String,Object> returnMap=new HashMap<String,Object>();
		for (Map<String, Object> map : mapList) {
			String charge_name=map.get("charge_name").toString().replace(" ", "");
			if("机架".equals(charge_name)){
				returnMap.put("price15", map.get("unit_price"));
			}
			if("10A42U".equals(charge_name)){
				returnMap.put("price12", map.get("unit_price"));
			}
			if("13A42U".equals(charge_name)){
				returnMap.put("price14", map.get("unit_price"));
			}
			if("IP".equals(charge_name)){
				returnMap.put("unitIP", map.get("unit_price"));
			}
		}
		return returnMap;
	}
}
